package com.zizy.healthexpert.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.TextView;

import com.zizy.healthexpert.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Zizy on 2014/7/8.
 */
public class listAddDiseaseAdapter extends ArrayAdapter {

    private Context context=null;
    private int res=0;
    public static ArrayList<String> checkedList=new ArrayList<String>();// a public static variable saved checked disease id list
    public listAddDiseaseAdapter(Context context, int resource, List objects) {
        super(context, resource, objects);
        this.context=context;
        this.res=resource;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        //TODO
        ViewGroup viewGroup = (ViewGroup) View.inflate(context, res, null);//inflate
        final AddedDisease item=(AddedDisease)getItem(position);
        /*getView*/
        final CheckBox chkAddedDisease=(CheckBox) viewGroup.findViewById(R.id.chkDisease);
         /*set View*/
        chkAddedDisease.setText(item.name);
        chkAddedDisease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (chkAddedDisease.isChecked()){ // if is checked added in the checked list
                    checkedList.add(String.valueOf(item.id)); //disease id
                }else{
                    checkedList.remove(String.valueOf(item.id));
                }
            }
        });
        //TODO

        return viewGroup;
    }

    //a class defined a type 'addedDishes' to describe the food.
    static  public class AddedDisease{
        public int id=0;
        public String name="";
        public ArrayList<Integer> goodToEatId=new ArrayList<Integer>();
        public ArrayList<Integer> notBadToEatId=new ArrayList<Integer>();
        public ArrayList<Integer> forbidToEatId=new ArrayList<Integer>();

        public AddedDisease(int id, String name, ArrayList<Integer> goodToEatId, ArrayList<Integer> notBadToEatId, ArrayList<Integer> forbidToEatId) {
            this.id = id;
            this.name = name;
            this.goodToEatId = goodToEatId;
            this.notBadToEatId = notBadToEatId;
            this.forbidToEatId = forbidToEatId;
        }
    }


}
